#coding=utf-8
from handlers.base.base_handler import BaseHandler
from libs.account.account_libs import edit_profile,send_email_libs,auth_email_libs
from libs.account.account_auth_libs import is_logined
import json
class ProfileHandler(BaseHandler):
    @is_logined
    def get(self):
        self.render('account/account_profile.html',message=None)

class ProfileEditHandler(BaseHandler):
    @is_logined
    def get(self):
        self.render('account/account_edit.html')
    @is_logined
    def post(self):
        name=self.get_argument('name','')
        password=self.get_argument('password','')
        result=edit_profile(self,name,password)
        if result['status'] is False:
            return self.render('account/account_profile.html',message=result['msg'])
        return self.render('account/account_profile.html',message=result['msg'])


class ProfileModifyEmailHandler(BaseHandler):
    @is_logined
    def get(self):
        self.render('account/account_send_email.html')
    @is_logined
    def post(self):
        email=self.get_argument('email','')
        result=send_email_libs(self,email)
        if result['status'] is True:
            return self.write(result['msg'])
        return self.write(result['msg'])

class ProfileAuthEmailHandler(BaseHandler):
    def get(self):
        email_code=self.get_argument('code','')
        email=self.get_argument('email','')
        u=self.get_argument('user_id','')
        print email_code,email,u
        result=auth_email_libs(self,email,email_code,u)
        if result['status'] is True:
            return self.redirect('/account/user_edit')
        return self.write(result['msg'])



